package top.lshaci.learning.springboot.web.fastjson.writer;

import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;

import java.lang.reflect.Type;
import java.time.Month;

/**
 * ObjectWriterMonth
 *
 * @author liangxu
 */
public class ObjectWriterMonth implements ObjectWriter<Month> {

    public static final ObjectWriterMonth INSTANCE = new ObjectWriterMonth();

    @Override
    public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
        if (object == null) {
            jsonWriter.writeNull();
            return;
        }

        Month month = (Month) object;
        jsonWriter.writeInt32(month.getValue());
    }
}
